package models

import (
	"github.com/go-xorm/xorm"
	"ju/src/single"
	"fmt"
)

var enginee *xorm.Engine

func init() {
	enginee = single.Get()
}

type Role struct {
	Id       int64
	RoleName string
	RoleDesc string
}

func SelRoleByName() []Role{

	var err error
	roles := make([]Role,0)
	err = enginee.Find(&roles)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(roles)
	return roles
}

func DelRoleById() {
	var dRole Role
	dRole.Id=6
	enginee.Delete(&dRole)
}

func UpdateRoleById() {
    var urole Role
	enginee.Id(5).Get(&urole)
	urole.RoleDesc="更新的中文测试"
	enginee.Id(5).Update(&urole)
}

func InsertOne()  {
	role := new(Role)
	role.RoleName="test"
	role.RoleDesc="测试用的中文"
	affected, err := enginee.Insert(role)
	if err != nil{
		fmt.Println(err)
	}
	fmt.Println(affected)
}
